<template>
  <el-container>
    <el-header>
      <div class="left-panel">
        <el-button v-if="$AUTH('system:sysParameterInit:add')" type="primary" icon="el-icon-plus" @click="add"></el-button>
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
			<selectBranchSystem :parentLoadingFunction="parentLoadingFunction" :parentGetData="parentGetData" :selectStyle="selectStyleInfo"/>
          <el-input v-model="search.parameterName" placeholder="名称" clearable style="width:10rem;"></el-input>
		  <el-select v-model="search.dataType" placeholder="类型" clearable style="width:8rem;">
			  <el-option label="单选框" value="1" /><el-option label="复选框" value="2" />
			  <el-option label="下拉框" value="5" /><el-option label="输入框" value="3" /><el-option label="textarea文本域" value="4" />
		  </el-select>
          <el-input v-model="search.numb" placeholder="编码" clearable style="width:10rem;"></el-input>
          <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding" v-loading="showloading">
      <scTable ref="table" :apiObj="apiObj" :loadNow="false" row-key="sysParameterId" @selection-change="selectionChange" stripe>
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column label="系统" prop="systemLevelId" width="100"></el-table-column>
        <el-table-column label="企业" prop="sysBranchOfficeId" width="100"></el-table-column>
        <el-table-column label="名称" prop="parameterName" width="100"></el-table-column>
        <el-table-column label="内容" prop="dataValue" width="550"></el-table-column>
        <el-table-column label="类型" width="100">
			<template #default="scope">
				<span v-if="scope.row.dataType==1">单选框</span><span v-if="scope.row.dataType==2">复选框</span><span v-if="scope.row.dataType==5">下拉框</span>
				<span v-if="scope.row.dataType==3">输入框</span><span v-if="scope.row.dataType==4">textarea文本域</span>
			</template>
		</el-table-column>
        <el-table-column label="备注" prop="msg" width="100"></el-table-column>
        <el-table-column label="编码" prop="numb" width="150"></el-table-column>
        <el-table-column label="排序" prop="seq" width="80"></el-table-column>
        <el-table-column label="操作" fixed="right" align="right">
          <template #default="scope">
            <el-button v-if="$AUTH('system:sysParameterInit:edit')" type="text" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
            <el-divider direction="vertical"></el-divider>
            <el-button v-if="$AUTH('system:sysParameterInit:del')" type="text" size="small" @click="table_del(scope.row, scope.$index)">删除</el-button>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>
  <sysParameterEdit-dialog v-if="dialog.sysParameterEdit" ref="sysParameterEditDialog" @success="handleSaveSuccess" @closed="dialog.sysParameterEdit=false"></sysParameterEdit-dialog>
</template>
<script>
  import systemAPI from '@/api/system/sysParameter';
  import sysParameterEditDialog from './sysParameterEdit';
  import selectBranchSystem from '@/components/glSelectCO/selectBranchSystem';
  export default {
    name: 'sysParameter',
    components: {
        sysParameterEditDialog,selectBranchSystem,
    },
    data() {
      return {
        dialog: {
          sysParameterEdit: false
        },
        apiObj: systemAPI.sysParameter.list,
        selection: [],
        search: {
          keyword: null,
          createTime: null,
		  dataType: null,
		  systemLevelId: null,
		  sysBranchOfficeId: null,
		  parameterName: null,
		  numb: null,
        },
		selectStyleInfo: "border:1px solid #f56c6c;width:15rem;",
		showloading: false,
      }
    },
    methods: {
      //添加
      add(){
        this.dialog.sysParameterEdit = true
        this.$nextTick(() => {
          this.$refs.sysParameterEditDialog.open()
        })
      },
      //编辑
      table_edit(row){
        this.dialog.sysParameterEdit = true
        this.$nextTick(() => {
          this.$refs.sysParameterEditDialog.open('edit').setData(row)
        })
      },
      //删除
      async table_del(row){
        var confirm = await this.$confirm('确定删除选中的项吗？', '提示', {
          confirmButtonText: 'ok',
          type: 'warning'
        }).catch(() => {})
        if(confirm !== 'confirm'){
          return false;
        }
        var res = await systemAPI.sysParameter.delete.delete(row.sysParameterId);
        if(res.code === 2000){
          this.$refs.table.refresh();
          this.$message.success("删除成功");
        }else{
          this.$alert(res.message, "提示", {type: 'error'});
        }
      },
      //表格选择后回调事件
      selectionChange(selection){
        this.selection = selection;
      },
      //搜索
      upsearch(){
		  if(!this.search.sysBranchOfficeId && !this.search.systemLevelId){
			  this.$message.warning("请您选择公司和系统！");
			  return false;
		  }
        this.$refs.table.upData(this.search);
      },
      //本地更新数据
      handleSaveSuccess(){
        this.$refs.table.refresh();
      },
      handlePermissionSuccess(){
        this.$refs.table.refresh();
      },
      handleDataSuccess(){
        this.$refs.table.refresh();
      },
      formatDate(row,column) {// 获取单元格数据
        let data = row[column.property];
        if(data == null) {
          return null;
        }
        let dt = new Date(data);
        return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate() + ' ' + dt.getHours() + ':' + dt.getMinutes() + ':' + dt.getSeconds();
      },
	  parentLoadingFunction(loadingBz){//选择 公司  分公司 回调函数 ---- 加载提醒
	  	this.showRoleloading = loadingBz;
	  	if(loadingBz)this.$refs.table.tableData=[];
	  },
	  parentGetData(sysBranchOfficeId,systemLevelId){//选择 公司  分公司 回调函数 ---- 重新获取数据
	  	this.search.sysBranchOfficeId = sysBranchOfficeId;
		this.search.systemLevelId = systemLevelId;
	  	this.$refs.table.tableData=[];//清空数据
	  	if(!this.search.sysBranchOfficeId && !this.search.systemLevelId)return true;
	  	this.$refs.table.upData(this.search);
	  },
    }
  }
</script>
<style>
</style>
